package com.xq.service.impl;

import cn.hutool.http.HttpUtil;
import com.xq.service.IdentityService;
import com.xq.utils.HttpClientUtils;
import com.xq.utils.MD5Sign;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


@Service
public class IdentityServiceImpl implements IdentityService {

    public static final int COREPOOLSIZW =Runtime.getRuntime().availableProcessors()*4;
    private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(COREPOOLSIZW,COREPOOLSIZW+30
            ,1L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(200));


    @Value("${msx.merId}")
    private String merId;

    @Value("${msx.appSercret}")
    private String appSercret;




    public String identityAuth(String name,String cardId,String base64FrontPic){
        String url="http://127.0.0.1:8080/api/common/identityAuth";
        Map<String,String> map = new HashMap<>();
        map.put("merId",merId);
        map.put("name",name);
        map.put("cardId",cardId);
        map.put("frontPic",base64FrontPic);
        String sign = MD5Sign.sign(map,appSercret);
        map.put("sign",sign);
        String str = HttpClientUtils.httpPost(url,map);
        return str;
    }


    public String liveAuth(String base64LivePic){
        String url="http://127.0.0.1:8080/api/common/liveAuth";
        Map<String,String> map = new HashMap<>();
        map.put("merId",merId);
        map.put("livePic",base64LivePic);

        String str = HttpClientUtils.httpPost(url,map);
        return str;
    }



    public static void main(String[] args) throws Exception {
        String url="http://127.0.0.1:8080/api/common/identityAuth";
        Map<String,String> map = new HashMap<>();
        map.put("merId","1001");
        map.put("name","大宝");
        map.put("cardId","4290003234312434523");
        map.put("frontPic","ffdsfsdfdfd");
        String sign = MD5Sign.sign(map,"aea43111aa87807fb79939b28256b929");
        map.put("sign",sign);
        String str = HttpClientUtils.httpPost(url,map);

    }















}
